package com.le.tester.imooc.ccmouse.socket;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * 描述：thread pool server
 */
public class ThreadPoolSever {
    public static void main(String[] args) throws IOException {

        ExecutorService executor = Executors.newFixedThreadPool(2);
        //监听6666端口
        RequestHandler requestHandler = new RequestHandler();
        try (ServerSocket serverSocket = new ServerSocket(7777)) {
            System.out.println("listening on " + serverSocket.getLocalSocketAddress());
            //服务端接受的一定是这个客户端的socket
            while (true) {
                Socket clientSocket = serverSocket.accept();
                System.out.println("accepting incoming connection from " + clientSocket.getRemoteSocketAddress());
                executor.submit(new ClientHandler(clientSocket, requestHandler));
            }
        }
    }
}
